package view;

/*
Cours :             LOG120 
Session :           Saison (hiver) 
Groupe :            01 
Projet :            Laboratoire #2
Etudiant(e)(s) :    Jeremy Moreau
                    Alexandre Richard
                    Philippe Pigeon
Code(s) perm. :     MORJ91010106
					RICA10028806 
                    PIGP08058903
Professeur :        Ghizlane El Boussaidi  
Date remise :       2012-03-010  
*/

import controller.CommandeController;
import controller.LivraisonController;
import java.awt.EventQueue;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JLabel;

public class LoginView extends JFrame implements ActionListener 
{

	private JPanel contentPane;
	private JTextField tbUsername;
	private JTextField tbPassw;
	
	private JButton btLogin;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					LoginView frame = new LoginView();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public LoginView() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 190, 207);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		//user
		JLabel lblNomDutilisateur = new JLabel("Nom d'utilisateur");
		lblNomDutilisateur.setBounds(23, 60, 110, 14);
		contentPane.add(lblNomDutilisateur);
		
		tbUsername = new JTextField();
		tbUsername.setBounds(23, 80, 134, 20);
		contentPane.add(tbUsername);
		tbUsername.setColumns(10);
		
		//pass
		JLabel lblMotDePasse = new JLabel("Mot de passe");
		lblMotDePasse.setBounds(23, 110, 87, 14);
		contentPane.add(lblMotDePasse);
		
		tbPassw = new JTextField();
		tbPassw.setBounds(23, 125, 134, 20);
		contentPane.add(tbPassw);
		tbPassw.setColumns(10);
		

		btLogin = new JButton("Login");
		btLogin.setBounds(54, 150, 50, 22);
		btLogin.addActionListener(this);
		contentPane.add(btLogin);
		
		//info
		JLabel lblInfo = new JLabel("<html><b>client</b>: Interface client<br><b>Autre</b>: Interface livraison</html>");
		lblInfo.setBounds(10, 0, 180, 50);
		contentPane.add(lblInfo);
	}

	@Override
	public void actionPerformed(ActionEvent ae) 
	{
		String username = tbUsername.getText();
		//tbPassw.getText();
		
		if(username.equalsIgnoreCase("client"))
			new CommandeController();
		else
			new LivraisonController();
	}
}
